<template>
    <div>
        <h1>登录</h1>
        <form @submit.prevent="login">
            <label>用户名: </label>
            <input v-model="username" type="text" />
            <br>
            <label>密码: </label>
            <input v-model="password" type="password" />
            <br>
            <button type="submit">登录</button>
        </form>
    </div>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { ref } from 'vue';

const router = useRouter();
const username = ref('');
const password = ref('');

const login = () => {
    if (username.value === 'admin') {
        localStorage.setItem('username', 'admin');
    } else {
        localStorage.setItem('username', username.value);
    }
    router.push('/');
};
</script>
    